<extend name="Public/block"/>
<block name="head">
    <!--<js file="__ROOT__/Public/js/layui/layui.js"/>-->
    <!--<css file="__ROOT__/Public/js/layui/css/layui.css"/>-->
    <js file="__SRC__/layer/layer.js"/>
    <js file="__SRC__/viewer/viewer.min.js"/>
    <css file="__SRC__/viewer/viewer.min.css"/>
    <js file="__JS__/UEditor/ueditor.parse.js" />
    <style>
        .syntaxhighlighter td.code{
            vertical-align: middle!important;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $(".content").viewer();
            $(function(){
                uParse('.content',{rootPath:'__JS__/UEditor'});
            });
        });
    </script>

</block>
<block name="left">
    <article class="blog-post">
        <div class="body">
            <h2 class="title">{$row.title}</h2>
            <div class="meta">
                <i class="fa fa-user"></i> {$row.author_name} <i class="fa fa-calendar"></i>{$row.post_date}<i
                    class="fa fa-comments"></i><span class="data"><a href="#comments">{$row.comments}</a>&nbsp;&nbsp;<i
                    class="fa fa-eye"></i> {$row.view}</span>
            </div>
            <div class="content">
                {$row.content}
            </div>
        </div>
        <aside class="social-icons clearfix">
            <h3>Share on </h3>
            <a href="#"><i class="fa fa-facebook"></i></a> <a href="#"><i class="fa fa-twitter"></i></a> <a href="#"><i
                class="fa fa-google"></i></a>
        </aside>
    </article>
    <if condition="$row['comments']">
        <!-- 回复列表 -->
        <aside class="comments" id="comments">
            <hr>
            <h2><i class="fa fa-comments"></i> {$row['comments']} Comments</h2>
            <!--评论输出-->
            <volist name="replies" id="vo">
                <label id="cmt{$vo.id}"></label>
                <article class="comment">
                    <header class="clearfix">
                        <img src="__PUBLIC__/img/0.png" alt="A Smart Guy" class="avatar">
                        <div class="meta">
                            <h3><a href="">{$vo.nickname}</a></h3>
                            <span class="date">
                        {$vo.create_time|smart_time}
                    </span>
                            <span class="separator">
                        -
                    </span>
                            <a href="#comment" class="reply-link" onclick="reply('{$vo.id}','{$vo.nickname}')">回复</a>
                        </div>
                        <div class="body">
                            {$vo.content}
                        </div>
                    </header>
                </article>
            </volist>
        </aside>
        <!--评论翻页条输出-->
        <div class="page commentpagebar">{$reply_page}</div>
    </if>
    <!-- 回复框 -->
    <aside class="create-comment" id="divCommentPost">
        <hr/>
        <p class="posttop"><a name="comment"></a></p>
        <h2><a name="comment"><i class="fa fa-pencil"></i> {:get_me('nickname')} 发表评论:</a></h2>
        <a rel="nofollow" id="cancel-reply" href="#divCommentPost" style="display:none;">
            <small>取消回复</small>
        </a>
        <form id="frmSumbit" target="_self" method="post" onsubmit="return post(this)"
              action="{:U('reply', ['post_id'=>$row['id']])}">
            {:tag('blog_reply_input_begin', $row)}
            <if condition="!get_me()">
                <div class="row">
                    <div class="col-md-6">
                        <input type="text" name="nickname" id="nickname" class="form-control input-lg"
                               placeholder="你的名字" value="{$blog_reply_info.nickname|default='访客'}" tabindex="1">
                    </div>
                    <div class="col-md-6">
                        <input type="email" name="email" id="email" class="form-control input-lg"
                               value="{$blog_reply_info.email}" placeholder="你的邮箱" tabindex="2">
                    </div>
                </div>
                <input type="url" name="website" id="website" placeholder="Website" class="form-control input-lg"
                       value="{$blog_reply_info.website}" tabindex="3">
                <else/>
                <input type="hidden" name="nickname" class="form-control input-lg" value="{:get_me('nickname')}">
                <input type="hidden" name="email" class="form-control input-lg" value="{:get_me('email')}"/>
            </if>
            <textarea name="content" id="content" placeholder="Your Message" class="form-control input-lg" rows="10"
                      tabindex="5"></textarea>
            {:tag('blog_reply_input_end', $row)}
            <div class="buttons clearfix">
                <input type="hidden" name="post_id" value="{$row.id}"/>
                <input type="hidden" id="reply_id" name="reply_id" value="0"/>
                <input type="submit" tabindex="6" value="提交" class="btn btn-xlarge btn-clean-one">
            </div>
        </form>
        <p class="postbottom">◎欢迎参与讨论，请在这里发表您的看法、交流您的观点。</p>
    </aside>
    <script type="text/javascript">
        function reply(id, nickname) {
            $('#reply_id').val(id);
            insertText($('#content')[0], '@' + nickname + ' ');
            $('#cancel-reply').show();
        }

        $('#cancel-reply').click(function () {
            $('#reply_id').val('');
            $(this).hide();
        });
        insertText = function (obj, str) {
            if (document.selection) {
                var sel = document.selection.createRange();
                sel.text = str;
            } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
                var startPos = obj.selectionStart,
                    endPos = obj.selectionEnd,
                    cursorPos = startPos,
                    tmpStr = obj.value;
                obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
                cursorPos += str.length;
                obj.selectionStart = obj.selectionEnd = cursorPos;
            } else {
                obj.value += str;
            }
        }

        function post(obj) {
            var data = $(obj).serialize();
            var url = $(obj).attr('action');
            var loading;
            $.ajax({
                url: url,
                data: data,
                type: $(obj).attr('method'),
                dataType: 'json',
                beforeSend: function () {
                    loading = layer.load(1, {shade: 0.3});
                },
                success: function (res) {
                    layer.close(loading);
                    layer.msg(res.info, {shade: 0.1, shadeClose: true}, function () {
                        if (res.url) window.location.href = res.url;
                    });
                },
                error: function () {
                    layer.close(loading);
                    layer.msg('加载失败');
                }
            });
            return false;
        }
    </script>
</block>